<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<!DOCTYPE html>
<html lang="en">
  <head>
     <%@include file="/WEB-INF/jsp/common/style.jsp"%>
  </head>
  <body>
    <div id="wrap">
    <input  type="hidden" id="roleId" value="${model.roleId}"/>
	
    <div   class="container-fluid">
     
      <!-- Main window -->
      <div class="main_container" id="dashboard_page">

		 <div class="row-fluid">
          <div class="widget widget-padding span12">
          
		  <div class="row-fluid" style="background-color:#fff;padding:20px 20px;">
               <div class="table-scroll">
                   <table  style="line-height: 40px; text-align: left;padding:20px 20px" >
                       <tr>
                           <td width="70px">角色名称:</td>
                           <td>${model.productRole.roleName}</td>

                           <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                       </tr>

                   </table>
               </div>
        </div>
       </div>
      </div>
      
   
		<div class="row-fluid">
          <div class="widget widget-padding span12">
            <div class="widget-header">
              <i class="icon-group"></i>
              <h5>权限列表</h5>
            
            </div>  
            <div class="widget-body">
              <table id="users" class="table table-striped table-bordered dataTable">
                <thead>
                  <tr>
                   <th>一级菜单</th>
                   	<th>二级菜单</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <c:forEach items="${model.items}" var="item" varStatus="itemStatus">
                    	<tr>     
                    		<td>                   			
                    			<c:if test="${item.menuId1!=null}">
	                    			<label class="checkbox"> 
	                    			<input name="menu1" type="checkbox" 
	                    			<c:if test="${item.select1==1}">
	                    				checked="checked" 
	                    			</c:if>  	                    			
	                    			 menuid="${item.menuId1}" 
	                    			 id="menuId_${item.menuId1}" value="${item.menuId1}">
	                    			${item.menuId1Name}
	                    			</label>
                    			</c:if>                  			
                    		</td>    
                    		<td>
                    			<c:if test="${item.menuId2!=null}">
	                    			<label class="checkbox"> 
	                    			<input name="menu2" type="checkbox" 
	                    			<c:if test="${item.select2==1}">
	                    				checked="checked" 
	                    			</c:if>  
	                    			 menuid="${item.menuId2}" id="menuId_${item.menuId2}" value="${item.menuId2}">
	                    			${item.menuId2Name}
	                    			</label>
                    			</c:if>       
                    		</td> 
                    		   
                  		</c:forEach>                                                
                  </tr>
                 
                </tbody>
              </table>
            </div> <!-- /widget-body -->
          </div> <!-- /widget -->
        </div> <!-- /row-fluid -->
        <div class="row-fluid">
          		<button class="btn btn-primary" type="submit"  onclick="selectall()">全选</button>
               <button class="btn btn-primary" type="button" onclick="save()">保存</button>
          	</div>

    </div>
    </div><!-- wrap ends-->
    </div>
  </body>
  <script type="text/javascript">
  function selectall() {	  
	    $("#users :checkbox").attr("checked", true);   
	    //checkCount();
	}	
    var postData;
	function save(){	
		postData="roleId=" + $('#roleId').val();
		var flag=false;
		$("#users tbody tr input").each(function () {
			var id=$(this).attr('id');
			var name=$(this).attr('name');
			var value=$(this).val();
			if ($(this).attr("checked") == "checked") {
			//	alert(id + " name:" +  name + " value:" +value)
				if(name=='menu1'){
					//选择一级菜单
					postData=postData + "&menuId1s=" + value;
					flag=true;
				}
				if(name=='menu2'){
					//选择二级菜单
					postData=postData + "&menuId2s=" + value;
					flag=true;
				}
				
			}			
		});
		if(flag){
			sendOpTo(postData);
		}
	}
	function sendOpTo(){
		//alert(postData);
		layer.load(1, {shade: [0.5,'#fff']});
		
		 $.ajax({
	            type: "POST",
	            url: "configSave",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	
    function editReturn() {
       layer.closeAll();
       oksubmit();
    }
    function closeAll() {
        layer.closeAll();
     }
    function edit(id){
		var domainUrl="edit?roleId=" + id;
		
		 $('#wrap').hide();
	     $('#editFrame').attr("src", domainUrl);
	     $('#edit').show(); 
	}
	function reset(userId){
		var postData="userId=" + userId;
		 $.ajax({
	            type: "POST",
	            url: "resetPassword",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	</script>
</html>
